<template>
  <div class="global-bases">
    <section class="content-section">
      <section class="filter-section">
        <div class="filter">
          <div class="filter-item-region">
            <span class="filter-label">地域:</span>
            <div class="button-group">
              <button :class="{'active': selectedRegion === 'ALL'}" @click="selectRegion('ALL')">{{ $t('globalbases.All') }}</button>
              <button :class="{'active': selectedRegion === 'INTERNATIONAL'}" @click="selectRegion('INTERNATIONAL')">{{ $t('globalbases.International') }}</button>
              <button :class="{'active': selectedRegion === 'CHINA'}" @click="selectRegion('CHINA')">{{ $t('globalbases.China') }}</button>
            </div>
          </div>
          <div class="filter-item-country">
            <span class="filter-label">国家/省份:</span>
            <div class="button-group">
              <button v-for="country in filteredCountries"
                      :key="country.value"
                      :class="{'active': selectedCountry === country.value}"
                      @click="selectCountry(country.value)">
                {{ $t(`globalbases.${country.text}`) }}
              </button>
            </div>
          </div>
        </div>
      </section>
      <div class="container">
        <div class="grid lg:grid-cols-3 gap-8">
          <div v-for="item in filteredItems" :key="item.company">
            <div class="card">
              <div class="card-image">
                <img :src="item.imageSrc" alt="Card Image" class="image">
              </div>
              <div class="card-content">
                <div class="location">
                  <span class="city">{{ $t(`globalbases.${item.city}`) }}</span>
                  <span class="company">{{ $t(`globalbases.${item.company}`) }}</span>
                </div>
                <p class="card-description">
                  <span class="label">{{ $t('globalbases.Label') }}</span>
                  {{ $t(`globalbases.${item.address}`) }}
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  name: 'GlobalBasesIsLogin',
  data() {
    return {
      selectedRegion: 'ALL',
      selectedCountry: 'ALL',
      countries: [
        { value: 'ALL', text: 'All' },
        { value: 'USA', text: 'USA' },
        { value: 'CH', text: 'CH' },
        { value: 'UK', text: 'UK' },
        { value: 'HK', text: 'HK' },
        { value: 'GD', text: 'GD' }
      ],
      items: [
        {
          city: 'USA',
          company: 'MBC',
          address: 'MBCAddress',
          imageSrc: require('@/assets/bases/MBC BioLabs.png'),
          match: {
            regions: ['INTERNATIONAL'],
            countries: ['USA']
          }
        },
        {
          city: 'UK',
          company: 'Cambridge',
          address: 'CambridgeAddress',
          imageSrc: require('@/assets/bases/jianqiao.png'),
          match: {
            regions: ['INTERNATIONAL'],
            countries: ['UK']
          }
        },
        {
          city: 'CH',
          company: 'BioAlps',
          address: 'BioAlpsAddress',
          imageSrc: require('@/assets/bases/BioAlps.png'),
          match: {
            regions: ['INTERNATIONAL'],
            countries: ['CH']
          }
        },
        {
          city: 'HK',
          company: 'chuangxin',
          address: 'chuangxinAddress',
          imageSrc: require('@/assets/bases/chuangkeyuan.png'),
          match: {
            regions: ['CHINA'],
            countries: ['HK']
          }
        },
        {
          city: 'HK',
          company: 'kejiyuan',
          address: 'kejiyuanAddress',
          imageSrc: require('@/assets/bases/kejiyuan.png'),
          match: {
            regions: ['CHINA'],
            countries: ['HK']
          }
        },
        {
          city: 'GD',
          company: 'yigu',
          address: 'yiguAddress',
          imageSrc: require('@/assets/bases/guangdongyigu.png'),
          match: {
            regions: ['CHINA'],
            countries: ['GD']
          }
        },
        {
          city: 'GD',
          company: 'shenzhen',
          address: 'shenzhenAddress',
          imageSrc: require('@/assets/bases/shenzhen.png'),
          match: {
            regions: ['CHINA'],
            countries: ['GD']
          }
        },
        {
          city: 'GD',
          company: 'guigu',
          address: 'guiguAddress',
          imageSrc: require('@/assets/bases/guigu.png'),
          match: {
            regions: ['CHINA'],
            countries: ['GD']
          }
        },
        {
          city: 'GD',
          company: 'xietong',
          address: 'xietongAddress',
          imageSrc: require('@/assets/bases/jingguangxietong.png'),
          match: {
            regions: ['CHINA'],
            countries: ['GD']
          }
        },
      ],
      filteredItems: [],
      filteredCountries: []
    };
  },
  created() {
    this.filterItems();
    this.updateFilteredCountries();
  },
  watch: {
    selectedRegion() {
      this.updateFilteredCountries();
    }
  },
  methods: {
    selectRegion(region) {
      this.selectedRegion = region;
      this.selectedCountry = 'ALL'; // 添加这行
      this.filterItems();
      this.updateFilteredCountries();
    },
    selectCountry(country) {
      this.selectedCountry = country;
      this.filterItems();
    },
    filterItems() {
      this.filteredItems = this.items.filter(item => {
        const regionMatches = this.selectedRegion === 'ALL' || item.match.regions.includes(this.selectedRegion);
        const countryMatches = this.selectedCountry === 'ALL' || item.match.countries.includes(this.selectedCountry);
        return regionMatches && countryMatches;
      });
    },
    updateFilteredCountries() {
      if (this.selectedRegion === 'ALL') {
        this.filteredCountries = this.countries;
      } else if (this.selectedRegion === 'INTERNATIONAL') {
        this.filteredCountries = this.countries.filter(c => ['ALL', 'USA', 'UK', 'CH'].includes(c.value));
      } else if (this.selectedRegion === 'CHINA') {
        this.filteredCountries = this.countries.filter(c => ['ALL', 'HK', 'GD'].includes(c.value));
      }
    }
  }
};
</script>

<style scoped>

.filter-section {
  margin-bottom: 1%;
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  font-size: 1.2vw;
}

.filter-item-region {
  display: flex;
  align-items: center;
  margin-bottom: 1%;
  font-size: 1.2vw;
}

.filter-item-country {
  display: flex;
  align-items: center;
  margin-top: -1%;
  font-size: 1vw;

}

.filter-label {
  margin-left: 1%;
  margin-right: 1rem;
  font-weight: bold;
  font-size: 1vw;
}

.button-group {
  display: flex;
  gap: 1vw;
}

button {
  background: none; /* 删除背景 */
  border: none; /* 删除边框 */
  color: #000000; /* 按钮文本颜色 */
  padding: 0.5rem 1rem; /* 内边距 */
  font-size: 1vw;
  cursor: pointer; /* 鼠标指针样式 */
  transition: color 0.3s ease; /* 颜色变化过渡 */

}

button.active {
  background-color: #92cafd;
  color: white;
}


.global-bases {
  font-family: Arial, sans-serif;
}

.content-section {
  width: 100%;
  padding: 3% 8% 0 10%; /* 保持上下内边距，左右内边距增加 */
}

.container {
  max-width: 100vw; /* 占满父元素宽度 */
  padding: 0;
  margin: 0 auto; /* 保持居中 */
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr); /* 固定三列 */
  gap: 2%; /* 网格间距 */
}

.card {
  display: flex;
  flex-direction: column;
  background-color: #f3f4f6;
  color: #1f2937;
  width: 90%;
  height: 90%;
  top: 2%;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  transform: translateY(-10px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.card-image {
  height: 70%;
}

.card-image .image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-content {
  padding: 1rem;
}

.location {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 1vw;
}

.city {
  background-color: #f8c38d;
  color: #000000;
  padding: 0.1rem 0.3rem;
  margin-right: 0.5rem;
  border-radius: 0.4rem;
  font-size: 0.9vw; /* 保持字体大小 */
}

.company {
  font-weight: bold;
  font-size: 1vw;
}

.label {
  font-size: 0.9vw;
  color: #ffab5e;
}

.card-description {
  font-size: 0.9vw;
}

@media (max-width: 768px) {
  .grid {
    grid-template-columns: repeat(3, 1fr); /* 保持三列 */
    gap: 1.5rem; /* 调整小屏幕上的网格间距 */
  }
}

@media (max-width: 480px) {
  .location {
    font-size: 10px; /* 调整字体大小 */
  }

  .city {
    font-size: 10px; /* 调整字体大小 */
    padding: 0.1rem 0.2rem; /* 调整内边距 */
  }

  .company {
    font-size: 12px; /* 调整字体大小 */
  }

  .card-description {
    font-size: 8px; /* 调整字体大小 */
  }
}
</style>
